<template>
  <div>
    <!-- 面包屑导航区域 -->
    <el-breadcrumb separator="/">
      <el-breadcrumb-item :to="{ path: '/home' }">首页</el-breadcrumb-item>
      <el-breadcrumb-item>订单管理</el-breadcrumb-item>
      <el-breadcrumb-item>订单列表</el-breadcrumb-item>
    </el-breadcrumb>
    <!-- 卡片区 -->
    <el-card>
      <!-- 间距 -->
      <el-row :gutter="20">
        <el-col :span="8">
          <!-- 查询用户 -->
          <el-input placeholder="请输入内容" clearable>
            <el-button slot="append" icon="el-icon-search"></el-button>
          </el-input>
        </el-col>
      </el-row>
      <!-- 列表区 -->
      <el-table :data="orderList" border stripe>
        <!-- 添加#有这个会让表格没对齐 -->
        <el-table-column type="index" label="#"></el-table-column>
        <el-table-column prop="order_number" label="订单编号">
        </el-table-column>
        <el-table-column prop="order_price" label="订单价格"> </el-table-column>
        <el-table-column prop="pay_status" label="是否付款"
          ><template slot-scope="scope">
            <el-tag v-if="scope.row.pay_status === '0'" type="danger"
              >未付款</el-tag
            ><el-tag v-else type="success">已付款</el-tag>
          </template>
        </el-table-column>
        <el-table-column prop="is_send" label="是否发货"> </el-table-column>
        <el-table-column prop="create_time" label="下单时间">
          <template slot-scope="scope">
            {{ scope.row.create_time | dataFormat }}
          </template>
        </el-table-column>
        <el-table-column label="操作">
          <template>
            <el-button
              type="primary"
              icon="el-icon-edit"
              size="mini"
              @click="showBox"
            ></el-button>
            <!-- 物流进度 -->
            <el-button
              type="success"
              icon="el-icon-location"
              size="mini"
              @click="showwuliu"
            ></el-button> </template
        ></el-table-column>
      </el-table>
      <!-- 分页 -->
      <el-pagination
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :current-page="queryIofo.pagenum"
        :page-sizes="[1, 2, 6, 10]"
        :page-size="queryIofo.pagesize"
        layout="total, sizes, prev, pager, next, jumper"
        :total="total"
        background
      >
      </el-pagination>
    </el-card>
    <!-- 省市联动框 -->
    <el-dialog
      title="编辑地址"
      :visible.sync="adessdialogVisible"
      width="50%"
      @close="showBoxclose"
    >
      <div>
        <el-form
          :model="addressForm"
          :rules="addressFormRules"
          ref="addressFormRef"
          label-width="80px"
          status-icon
        >
          <el-form-item label="省市区/县" prop="adress1">
            <el-cascader
              expand-trigger="hover"
              :options="cityData"
              v-model="addressForm.adress1"
              clearable
            >
            </el-cascader>
          </el-form-item>
          <el-form-item label="详细地址" prop="adress2">
            <el-input v-model="addressForm.adress2"></el-input>
          </el-form-item>
        </el-form>
      </div>
      <span slot="footer" class="dialog-footer">
        <el-button @click="adessdialogVisible = false">取 消</el-button>
        <el-button type="primary" @click="adessdialogVisible = false"
          >确 定</el-button
        >
      </span>
    </el-dialog>
    <el-dialog title="物流进度" :visible.sync="wuliudialogVisible" width="50%">
      <div>
        <!-- 时间线 -->
        <el-timeline>
          <el-timeline-item
            v-for="(activity, index) in wuliu"
            :key="index"
            :timestamp="activity.time"
          >
            {{ activity.context}}
          </el-timeline-item>
        </el-timeline>
      </div>
    </el-dialog>
  </div>
</template>

<script>
// 拿到省市联动数据
import cityData from './citydata'
// 测试物流数据
import wuliu from './wuliu'
export default {
  data () {
    return {
      // 获取订单列表参数
      queryIofo: {
        // 搜索参数
        query: '',
        // 当前页码
        pagenum: 1,
        // 页面数据条数
        pagesize: 6
      },
      //   订单列表
      orderList: [],
      total: 0,
      //   默认显示状态
      adessdialogVisible: false,
      wuliudialogVisible: false,
      addressForm: {
        adress1: [],
        adress2: ''
      },
      addressFormRules: {
        adress2: [
          {
            required: true,
            message: '请输入详细地址',
            trigger: 'blur'
          }
        ]
      },
      cityData,
      wuliu
      //   wuliuIofo:[]
    }
  },
  created () {
    this.getOderlist()
  },
  methods: {
    async getOderlist () {
      const { data: res } = await this.$http.get('orders', {
        params: this.queryIofo
      })
      if (res.meta.status !== 200) { return this.$message.error('获取订单列表失败') }
      //   console.log(res);
      this.$message.success('获取订单列表成功')
      this.orderList = res.data.goods
      this.total = res.data.total
    },
    // 监听页面数改变事件
    handleSizeChange (newSize) {
      // 重新获取页面数据
      this.queryIofo.pagesize = newSize
      this.getOderlist()
    },
    // 监听页码改变事件
    handleCurrentChange (newPage) {
      this.queryIofo.pagenum = newPage
      this.getOderlist()
    },
    // 展示编辑地址对话框
    showBox () {
      this.adessdialogVisible = true
    },
    // 重置事件
    showBoxclose () {
      this.$refs.addressFormRef.resetFields()
    },
    // 展示地址对话框
    async showwuliu () {
      //   测试没有借口就算了用静态文件
      //   const { data: res } = await this.$http.get("/kuaidi/1106975712662");
      //   if (res.meta.status !== 200)
      //     return this.$message.error("物流进度查询失败");
      //     this.wuliuIofo=res.data
      //     console.log(this.wuliuIofo)
      this.wuliudialogVisible = true
    }
  }
}
</script>

<style Lang="less" scoped>
</style>
